using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using NUnit.Framework;
using SCSFContrib.CompositeUI.WPF.CommandAdapters;
using Microsoft.Practices.CompositeUI.Commands;

namespace SCSFContrib.CompositeUI.WPF.UnitTest.CommandAdapters
{
	[TestFixture]
	public sealed class UIElementCommandAdapterTest : UnitTest
	{
		private UIElementCommandAdapter _uiElementCommandAdapter;
		private UIElement _invoker;

		protected override void SetUpCore()
		{
			base.SetUpCore();
			_invoker = new UIElement();
			_uiElementCommandAdapter = new UIElementCommandAdapter(_invoker, "GotFocus");
		}

		[Test]
		public void Constructor_Default_ShouldDoNothing()
		{
			_uiElementCommandAdapter = new UIElementCommandAdapter();
			Assert.AreEqual(0, _uiElementCommandAdapter.InvokerCount);
		}

		[Test]
		public void OnCommandChanged_ShouldDisableUIElementIfCommandIsDisabled()
		{
			Command command = new Command();
			command.Status = CommandStatus.Disabled;

			Assert.IsTrue(_invoker.IsEnabled);
			InvokePrivateMethod<object>(_uiElementCommandAdapter, "OnCommandChanged", command);
			Assert.IsFalse(_invoker.IsEnabled);
		}

		[Test]
		public void OnCommandChanged_ShouldEnableUIElementIfCommandIsEnabled()
		{
			Command command = new Command();
			command.Status = CommandStatus.Enabled;

			_invoker.IsEnabled = false;
			Assert.IsFalse(_invoker.IsEnabled);
			InvokePrivateMethod<object>(_uiElementCommandAdapter, "OnCommandChanged", command);
			Assert.IsTrue(_invoker.IsEnabled);
		}

		[Test]
		public void OnCommandChanged_ShouldHideUIElementIfCommandIsUnavailable()
		{
			Command command = new Command();
			command.Status = CommandStatus.Unavailable;

			Assert.AreEqual(Visibility.Visible, _invoker.Visibility);
			InvokePrivateMethod<object>(_uiElementCommandAdapter, "OnCommandChanged", command);
			Assert.AreEqual(Visibility.Collapsed, _invoker.Visibility);
		}

		[Test]
		public void OnCommandChanged_ShouldDisplayUIElementIfCommandIsAvailable()
		{
			Command command = new Command();
			command.Status = CommandStatus.Enabled;

			_invoker.Visibility = Visibility.Hidden;
			Assert.AreEqual(Visibility.Hidden, _invoker.Visibility);
			InvokePrivateMethod<object>(_uiElementCommandAdapter, "OnCommandChanged", command);
			Assert.AreEqual(Visibility.Visible, _invoker.Visibility);
		}
	}
}
